package com.fitc.imageprocessing;

import ij.ImagePlus;
import ij.process.ImageProcessor;

public class BucketHistogram {

	ImageProcessor _ip;
	int[] _bucket;
	
	BucketHistogram (ImagePlus in){
		this._ip = in.getProcessor();
		process(8);
	}
	
	private void process(int numBuckets){
		int hist[] = _ip.getHistogram();
		
		int bucketWidth = hist.length/numBuckets;
		_bucket = new int[numBuckets];
		
		int sum = 0;
		int bucketCount = 0;
		for (int i=1;i<=hist.length;i++){
			sum += hist[i-1];
			if (i%bucketWidth==0){
				_bucket[bucketCount]= sum;
				bucketCount++;
				sum=0;
			}
		}
	}
	
	public int[] getBucketHistogram(){
		return _bucket;
	}
	
	@Override
	public String toString(){
		String str ="";
		for (int b:_bucket){
			str += ":" + b;
		}
		return str;
	}

}
